package com.itheima.mm.mapper;

import com.github.pagehelper.Page;
import com.itheima.mm.entity.CoursePageQueryParams;
import com.itheima.mm.pojo.Course;
import com.itheima.mm.vo.CourseVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description CourseMapper
 * @Author xiao
 * @Date 2024-06-22
 */
@Mapper
public interface CourseMapper {
    void insert(Course course);


    //获取学科数量总数Total
    Long countByCondition(CoursePageQueryParams queryParams);
    //获取当前页的数据列表
    List<CourseVO> findByConditon(Integer start, Integer length, CoursePageQueryParams queryParams);


         //使用PageHelper插件实现分页操作
    Page<CourseVO> findByConditon2(CoursePageQueryParams queryParams);


    //更新学科
    void update(Course course);


    //删除学科，根据学科id获取学科关联数据
    @Select("select\n" +
            "       (select count(*) from t_catalog where course_id = tc.id) catalogQty,\n" +
            "       (select count(*) from t_tag where course_id = tc.id) tagQty,\n" +
            "       (select count(*) from t_question where course_id = tc.id) questionQty\n" +
            "from t_course tc\n" +
            "where tc.id = #{id}\n")
    CourseVO findById(Integer id);


    //根据学科id删除学科
    @Select("delete from t_course where id = #{id}")
    void deleteById(Integer id);


    @Select("select * from t_course")
    List<Course> findListAll();







}


